//
//  AWVisitorController.swift
//  WeiBo
//
//  Created by AaronWei on 2017/6/5.
//  Copyright © 2017年 AaronWei. All rights reserved.
//

import UIKit

class AWVisitorController: UITableViewController {
    
    var visitorView: AWVisitorView?
    
    var isLogin: Bool = AWUserAccountViewModel.sharedViewModel.isLogin
    
    override func loadView() {
        
        if isLogin {
            
            super.loadView()
            
        } else {
            
            setupBarButtonItem()
            
            visitorView = AWVisitorView()
            
            visitorView?.loginCallBack = {
            
                self.presentLoginView()
                
            }
            
            visitorView?.registerCallBack = {
                
                print("注册")
                
            }
                        
            view = visitorView
            
        }
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()

//        setupBarButtonItem()
        
    }
    
    func setupBarButtonItem() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(leftBarButtonDidClicked))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(rightBarButtonDidClicked))
        
    }
    
    @objc private func leftBarButtonDidClicked() {
        
        print("注册")
        
    }
    
    @objc private func rightBarButtonDidClicked() {
        
        presentLoginView()
        
    }
    
    private func presentLoginView() {
       
        present(UINavigationController(rootViewController: AWOAuthController()), animated: true, completion: nil)
        
    }

}
